home *** CD-ROM | disk | FTP | other *** search
/ Czech Logic, Card & Gambling Games / Logické hry.iso / hry / Fish Fillets / script / stairs / code.lua next >
Text File  |  2005-07-16  |  8KB  |  231 lines

  1.  
  2. -- -----------------------------------------------------------------
  3. -- Init
  4. -- -----------------------------------------------------------------
  5. local function prog_init()
  6.     initModels()
  7.     sound_playMusic("music/rybky03.ogg")
  8.     local pokus = getRestartCount()
  9.  
  10.  
  11.     -- -------------------------------------------------------------
  12.     local function prog_init_room()
  13.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  14.  
  15.         switch(pokus){
  16.             [1] = function()
  17.                 room.uvod = 0
  18.             end,
  19.             [2] = function()
  20.                 room.uvod = 1
  21.             end,
  22.             default = function()
  23.                 room.uvod = random(4)
  24.             end,
  25.         }
  26.         room.setk = 0
  27.         if pokus == 1 then
  28.             room.prehnala = 22
  29.         else
  30.             room.prehnala = 21
  31.         end
  32.  
  33.         return function()
  34.             if isReady(small) and isReady(big) and no_dialog() then
  35.                 if room.uvod < 3 then
  36.                     switch(room.uvod){
  37.                         [0] = function()
  38.                             addm(random(30), "sch-m-spadlo")
  39.                         end,
  40.                         [1] = function()
  41.                             addm(random(30), "sch-m-spadlo")
  42.                             addv(random(30), "sch-v-lastura")
  43.                         end,
  44.                         [2] = function()
  45.                             addv(random(30), "sch-v-lastura")
  46.                         end,
  47.                     }
  48.                     room.uvod = 3
  49.                 elseif plzik.X >= room.prehnala then
  50.                     addm(random(40), "sch-m-moc"..random(3))
  51.                     room.prehnala = 100
  52.                 elseif room.setk == 0 and plzik.X == 10 and plzik.Y == 14 then
  53.                     addv(random(40), "sch-v-setkani")
  54.                     room.setk = 1
  55.                 end
  56.             end
  57.         end
  58.     end
  59.  
  60.     -- -------------------------------------------------------------
  61.     local function prog_init_plzik()
  62.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  63.  
  64.         plzik.stav = 0
  65.  
  66.         return function()
  67.             if plzik.dir ~= dir_no then
  68.                 plzik.stav = 15
  69.             end
  70.             if isWater(plzik.X + 1, plzik.Y + 2) then
  71.                 plzik.stav = 10
  72.             end
  73.             switch(plzik.stav){
  74.                 [0] = function()
  75.                     plzik.afaze = 0
  76.                     if random(100) < 2 then
  77.                         plzik.stav = plzik.stav + 1
  78.                     end
  79.                 end,
  80.                 [1] = function()
  81.                     plzik.afaze = 5
  82.                     plzik.stav = plzik.stav + 1
  83.                 end,
  84.                 [2] = function()
  85.                     plzik.afaze = random(3) + 1
  86.                     plzik.stav = plzik.stav + 1
  87.                 end,
  88.                 [3] = function()
  89.                     if odd(game_getCycles()) then
  90.                         if random(100) < 20 then
  91.                             plzik.afaze = random(3) + 1
  92.                         end
  93.                     end
  94.                     if random(1000) < 5 then
  95.                         plzik.stav = plzik.stav + 1
  96.                     end
  97.                 end,
  98.                 [4] = function()
  99.                     plzik.afaze = 5
  100.                     plzik.stav = 0
  101.                 end,
  102.                 [10] = function()
  103.                     plzik.afaze = 4
  104.                     if isWater(plzik.X + 1, plzik.Y + 2) then
  105.                         plzik.stav = 21 + random(20)
  106.                     end
  107.                 end,
  108.                 [15] = function()
  109.                     plzik.afaze = 5
  110.                     if plzik.dir == dir_no then
  111.                         plzik.stav = 21 + random(20)
  112.                     end
  113.                 end,
  114.                 [20] = function()
  115.                     plzik.stav = 3
  116.                 end,
  117.                 default = function()
  118.                     if plzik.stav >= 21 or plzik.stav <= 100 then 
  119.                         plzik.stav = plzik.stav - 1
  120.                     end
  121.                 end,
  122.             }
  123.             plzik:updateAnim()
  124.         end
  125.     end
  126.  
  127.     -- -------------------------------------------------------------
  128.     local function prog_init_snecek()
  129.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  130.  
  131.         snecek.cinnost = 0
  132.         snecek.sour = random(6) * 3
  133.         snecek.smer = random(2) * 2 - 1
  134.  
  135.         return function()
  136.             switch(snecek.cinnost){
  137.                 [0] = function()
  138.                     if random(100) < 1 then
  139.                         snecek.cinnost = 1
  140.                     elseif random(100) < 2 then
  141.                         snecek.cinnost = 2
  142.                     end
  143.                 end,
  144.                 [1] = function()
  145.                     if random(100) < 3 then
  146.                         snecek.cinnost = 0
  147.                     end
  148.                 end,
  149.                 [2] = function()
  150.                     if math.mod(snecek.sour, 3) == 0 and random(100) < 30 then
  151.                         snecek.cinnost = 0
  152.                     elseif math.mod(snecek.sour, 3) == 0 and random(100) < 10 then
  153.                         snecek.cinnost = 3
  154.                     elseif random(100) < 2 or snecek.smer == -1 and snecek.sour == 0 or snecek.smer == 1 and snecek.sour == 15 then
  155.                         snecek.smer = -snecek.smer
  156.                     elseif snecek.smer < 0 then
  157.                         snecek.sour = snecek.sour - 1
  158.                     elseif snecek.smer > 0 then
  159.                         snecek.sour = snecek.sour + 1
  160.                     end
  161.                 end,
  162.                 [3] = function()
  163.                     if random(100) < 3 then
  164.                         snecek.cinnost = 2
  165.                     end
  166.                 end,
  167.             }
  168.             switch(snecek.cinnost){
  169.                 [0] = function()
  170.                     if snecek.smer < 0 then
  171.                         snecek.afaze = 15 - snecek.sour
  172.                     else
  173.                         snecek.afaze = 22 + snecek.sour
  174.                     end
  175.                 end,
  176.                 [2] = function()
  177.                     if snecek.smer < 0 then
  178.                         snecek.afaze = 15 - snecek.sour
  179.                     else
  180.                         snecek.afaze = 22 + snecek.sour
  181.                     end
  182.                 end,
  183.                 [1] = function()
  184.                     if snecek.smer < 0 then
  185.                         snecek.afaze = 21 - math.floor(snecek.sour / 3)
  186.                     else
  187.                         snecek.afaze = 38 + math.floor(snecek.sour / 3)
  188.                     end
  189.                 end,
  190.                 [3] = function()
  191.                     if snecek.smer < 0 then
  192.                         snecek.afaze = 21 - math.floor(snecek.sour / 3)
  193.                     else
  194.                         snecek.afaze = 38 + math.floor(snecek.sour / 3)
  195.                     end
  196.                 end,
  197.             }
  198.             snecek:updateAnim()
  199.         end
  200.     end
  201.  
  202.     -- --------------------
  203.     local update_table = {}
  204.     local subinit
  205.     subinit = prog_init_room()
  206.     if subinit then
  207.         table.insert(update_table, subinit)
  208.     end
  209.     subinit = prog_init_plzik()
  210.     if subinit then
  211.         table.insert(update_table, subinit)
  212.     end
  213.     subinit = prog_init_snecek()
  214.     if subinit then
  215.         table.insert(update_table, subinit)
  216.     end
  217.     return update_table
  218. end
  219. local update_table = prog_init()
  220.  
  221.  
  222. -- -----------------------------------------------------------------
  223. -- Update
  224. -- -----------------------------------------------------------------
  225. function prog_update()
  226.     for key, subupdate in pairs(update_table) do
  227.         subupdate()
  228.     end
  229. end
  230.  
  231.